home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / cuj0593.zip / 1105108B < prev    next >
Text File  |  1993-03-09  |  2KB  |  67 lines

  1. /* pr.c: Skeleton of a file printer program */
  2.       
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <ctype.h>
  6.       
  7. static int
  8.     Copies = 1,  /* Default to one copy */
  9.     Number = 0;  /* Don't print with line numbers */
  10. static char
  11.     Queue = 'S'; /* Default to standard printer */
  12.       
  13. static void process(char *);
  14.  
  15. main(int argc, char *argv[])
  16. {
  17.     int i;
  18.     char *s;
  19.           
  20.     /* Process each argument immediately */
  21.     for (i = 1; i < argc; ++i)
  22.     {
  23.         if (argv[i][0] == '-')
  24.             for (s = argv[i]+1; *s; ++s)
  25.                 switch(toupper(*s))
  26.                 {
  27.                 case 'C':   /* Build number for copies */
  28.                     if (isdigit(s[1]))
  29.                         for (Copies = 0; isdigit(s[1]); ++s)
  30.                             Copies = Copies*10 + (s[1] - '0');
  31.                     break;
  32.                 case 'N':   /* Toggle line numbering */
  33.                     Number = !Number;
  34.                     break;
  35.                 case 'Q':   /* Select print queue */
  36.                     ++s;
  37.                     Queue = toupper(*s);
  38.                     break;
  39.                 default:
  40.                     fprintf(stderr,"pr: Bad option: -%c\n",*s);
  41.                     return EXIT_FAILURE;
  42.                 }
  43.         else
  44.             process(argv[i]);
  45.     }
  46.     return EXIT_SUCCESS;
  47. }
  48.  
  49. static void process(char *s)
  50. {
  51.     printf("Processing %s...\n",s);
  52.     printf("\tCopies: %d, Number: %d, Queue: %c\n", 
  53.       Copies,Number,Queue);
  54. }
  55.  
  56. /* The output after executing the command line above is
  57.  
  58. Processing file1.c...
  59.     Copies: 10, Number: 1, Queue: S
  60. Processing file2.c...
  61.     Copies: 1, Number: 0, Queue: L
  62. Processing file3.c...
  63.     Copies: 1, Number: 0, Queue: L
  64.  
  65. */
  66.  
  67.